package com.dkd.http.controller;

import com.dkd.entity.VendingMachineEntity;
import com.dkd.entity.dto.ApplyPolicyDto;
import com.dkd.entity.dto.RepairCountDto;
import com.dkd.entity.dto.VmDto;
import com.dkd.entity.dto.VmQuery;
import com.dkd.entity.vo.VmPageVo;
import com.dkd.entity.vo.VmVo;
import com.dkd.service.VendingMachineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 售货机管理
 */
@RestController
@RequestMapping("/vm")
@Slf4j
@RequiredArgsConstructor
@Api(tags = "售货机业务")
public class VendingMachineController {
    private final VendingMachineService vendingMachineService;
    @ApiOperation("新增售货机")
    @PostMapping
    public List<VmVo> addVm(@RequestBody VmDto vmDto ) {
        log.info("新增售货机");
        return vendingMachineService.addVm(vmDto);
    }
    @ApiOperation("修改售货机点位")
    @PutMapping("/{id}/{nodeId}")
    public void updateVm(@PathVariable("id") Long id,@PathVariable("nodeId") Long nodeId){
        log.info("修改售货机点位");
        vendingMachineService.updateVm(id,nodeId);
    }
    @ApiOperation("应用策略")
    @PutMapping("/applyPolicy")
    public boolean applyPolicy(@RequestBody ApplyPolicyDto applyPolicyDto){
        return vendingMachineService.applyPolicy(applyPolicyDto);
    }
    @ApiOperation("搜索售货机(售货机列表)")
    @GetMapping("/search")
    public VmPageVo pageVm(VmQuery vmQuery){
        return vendingMachineService.pageVm(vmQuery);
    }
    @ApiOperation("获取售货机详情")
    @GetMapping("/details/{innerCode}")
    public VendingMachineEntity getDetails(@PathVariable("innerCode") String innerCode){
        return vendingMachineService.getDetails(innerCode);
    }

    @PutMapping("/status/{vmId}/{status}")
    @ApiOperation("修改售货机状态")
    public boolean updateStatus(@PathVariable("vmId") Long vmId,@PathVariable("status") Integer status ){
        return vendingMachineService.updateStatus(vmId,status);
    }
    @GetMapping("/RepairCount")
    public List<VendingMachineEntity> repairCount( RepairCountDto repairCountDto){
        return vendingMachineService.repairCount(repairCountDto);
    }
}
